package experiment12;

import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;


public class No_4 extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) {

        BorderPane pane=new BorderPane();
        HBox select_box=new HBox();

        TextArea textArea=new TextArea();
        TextField filename=new TextField();
        Button view=new Button("View");
        select_box.getChildren().addAll(new Label("filename"),filename,view);

        select_box.setAlignment(Pos.CENTER);

        pane.setCenter(textArea);
        pane.setBottom(select_box);

        view.setOnAction(event -> {
            String filepath=filename.getText();
            try {
                Scanner input=new Scanner(new File(filepath));
                while (input.hasNext()){
                    textArea.appendText(input.nextLine()+"\n");
                }
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        });

        primaryStage.setTitle("text view");
        primaryStage.setScene(new Scene(pane));
        primaryStage.show();
    }
}
